package com.klikmee.sms.core.base;

import java.text.MessageFormat;

import org.apache.log4j.Logger;

import com.klikmee.sms.core.base.communicator.DeliveryReport;
import com.klikmee.sms.core.model.OutgoingMessage;

/**
 * Implementation of delivery report filter for charged messages. It uses
 * resolvers to resolve charged message and then delegates them to handler.
 * Steps: 1. Resolve charged message 2. Let handler update state of invoice, IM
 * and OM 3. Hand over delivery report to postman
 * 
 * @author makcro
 * 
 */
public class ChargedDeliveryReportFilterImpl extends DeliveryReportFilterBase<OutgoingMessage> {

	/**
	 * Logger instance
	 */
	Logger	logger	= Logger.getLogger( ChargedDeliveryReportFilterImpl.class );

	@Override
	protected void postReportToService(OutgoingMessage sentMessage) {
		// hand over outgoing mesage to
		this.serviceMessageDeliverer.forwardDeliveryReport( sentMessage );
	}

	@Override
	protected void updateStatus(DeliveryReport deliveryReport, OutgoingMessage sentMessage) {
		sentMessage.setDeliveryStatus( deliveryReport.getStatus() );
		logger.debug( MessageFormat.format( "Updated status of OutgoingMessage[{0}] to [{1}]", sentMessage.getId(), sentMessage.getDeliveryStatus() ) );
	}

}
